package com.CNMedical.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.diboot.core.binding.Binder;
import com.diboot.core.service.impl.BaseServiceImpl;
import com.CNMedical.common.utils.DateUtils;
import com.CNMedical.system.domain.DTO.AppletForumCommentDTO;
import com.CNMedical.system.domain.vo.AppletForumCommentVO;
import com.CNMedical.system.service.IAppletUserService;
import org.springframework.stereotype.Service;
import com.CNMedical.system.mapper.AppletForumCommentMapper;
import com.CNMedical.system.domain.entity.AppletForumComment;
import com.CNMedical.system.service.IAppletForumCommentService;

import javax.annotation.Resource;

/**
 * 论坛帖子留言Service业务层处理
 * 
 * @author tang
 * @date 2023-03-29
 */
@Service
public class AppletForumCommentServiceImpl extends BaseServiceImpl<AppletForumCommentMapper, AppletForumComment> implements IAppletForumCommentService
{
    @Resource
    private AppletForumCommentMapper appletForumCommentMapper;

    @Resource
    private IAppletUserService appletUserService;

    @Override
    public List<AppletForumCommentVO> getForumPostCommentByPostId(String postId) {
        List<AppletForumCommentVO> viewObjectList = this.getViewObjectList(Wrappers.lambdaQuery(AppletForumComment.class)
                        .eq(AppletForumComment::getForumId, postId)
                        .eq(AppletForumComment::getPid,0),
                null,
                AppletForumCommentVO.class
        );
        return viewObjectList;
    }

    /**
     * 查询论坛帖子留言
     * 
     * @param id 论坛帖子留言主键
     * @return 论坛帖子留言
     */
    @Override
    public AppletForumComment selectAppletForumCommentById(Long id)
    {
        return appletForumCommentMapper.selectAppletForumCommentById(id);
    }

    /**
     * 查询论坛帖子留言列表
     * 
     * @param appletForumComment 论坛帖子留言
     * @return 论坛帖子留言
     */
    @Override
    public List<AppletForumCommentVO> selectAppletForumCommentList(AppletForumCommentDTO appletForumComment)
    {
        List<Long> userIdList = appletUserService.getUserIdByUserName(appletForumComment.getUserName());
        List<AppletForumComment> appletForumComments = appletForumCommentMapper.selectAppletForumCommentList(appletForumComment,userIdList);
        List<AppletForumCommentVO> appletForumCommentVOS = Binder.convertAndBindRelations(appletForumComments, AppletForumCommentVO.class);
        return appletForumCommentVOS;
    }

    /**
     * 新增论坛帖子留言
     * 
     * @param appletForumComment 论坛帖子留言
     * @return 结果
     */
    @Override
    public int insertAppletForumComment(AppletForumComment appletForumComment)
    {
        appletForumComment.setCreateTime(DateUtils.getNowDate());
        return appletForumCommentMapper.insertAppletForumComment(appletForumComment);
    }

    /**
     * 修改论坛帖子留言
     * 
     * @param appletForumComment 论坛帖子留言
     * @return 结果
     */
    @Override
    public int updateAppletForumComment(AppletForumComment appletForumComment)
    {
        appletForumComment.setUpdateTime(DateUtils.getNowDate());
        return appletForumCommentMapper.updateAppletForumComment(appletForumComment);
    }

    /**
     * 批量删除论坛帖子留言
     * 
     * @param ids 需要删除的论坛帖子留言主键
     * @return 结果
     */
    @Override
    public int deleteAppletForumCommentByIds(Long[] ids)
    {
        return appletForumCommentMapper.deleteAppletForumCommentByIds(ids);
    }

    /**
     * 删除论坛帖子留言信息
     * 
     * @param id 论坛帖子留言主键
     * @return 结果
     */
    @Override
    public int deleteAppletForumCommentById(Long id)
    {
        return appletForumCommentMapper.deleteAppletForumCommentById(id);
    }
}
